/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.rocketmq.client.consumer;

import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

/**
 * Strategy Algorithm for message allocating between consumers
 */
public interface AllocateMessageQueueStrategy {

    /**
     * Allocating by consumer id
     *
     * @param consumerGroup current consumer group
     * @param currentCID current consumer id
     * @param mqAll message queue set in current topic
     * @param cidAll consumer set in current consumer group
     * @return The allocate result of given strategy
     */
    List<MessageQueue> allocate(
        final String consumerGroup,
        final String currentCID,
        final List<MessageQueue> mqAll,
        final List<String> cidAll
    );

    /**
     * Algorithm name
     *
     * @return The strategy name
     *
     * 有五种分配算法：
     * <br>1、平均分配：比如现在有八个队列q1-q8，三个消费者c1-c3，那么根据负载均衡算法：c1：q1-q3，以此类推。推荐使用
     * <br>2、平均轮询算法：比如现在有八个队列q1-q8，三个消费者c1-c3，那么根据负载均衡算法：c1：q1q4q7，c2：q2q5q8，c3：q3q6。推荐使用
     * <br>3、一致性hash：不推荐使用，因为消息队列负载信息不容易跟踪
     * <br>4、根据配置，为每一个消费者配置固定的消息队列
     * <br>5、根据broker部署机房名，对每个消费者负载不同的broker上的队列
     * <br>
     * <p>
     *     消息负载算法如果没有特殊的要求，尽量使用前两个<br>
     *     因为分配算法比较直观。队列分配一个消息者可以分配到多个消息队列，但是同一个队列只分配给一个消息者，故消费者大于消息队列的时候，有些消费者无法消费消息
     * </p>
     */
    String getName();
}
